package cn.stylefeng.guns.modular.api.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.rms.model.params.OuttaskApplyParam;
import cn.stylefeng.guns.modular.rms.model.params.OuttaskParam;
import cn.stylefeng.guns.modular.rms.model.result.OuttaskApplyResult;
import cn.stylefeng.guns.modular.rms.model.result.OuttaskResult;
import cn.stylefeng.guns.modular.rms.service.OuttaskApplyService;
import cn.stylefeng.guns.modular.rms.service.OuttaskService;
import cn.stylefeng.guns.modular.wms.model.params.BrowseParam;
import cn.stylefeng.guns.modular.wms.model.result.BrowseResult;
import cn.stylefeng.guns.modular.wms.service.BrowseService;
import cn.stylefeng.guns.utils.MemberTokenUtil;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.velocity.app.event.implement.EscapeXmlReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 *浏览记录模块管理
 */
@Controller
@RequestMapping("/api/browse")
@Api(tags = "浏览记录模块管理")
@CrossOrigin
public class ApiBrowseController extends BaseController {

    @Autowired
    private BrowseService browseService;

    /**
     * 查询浏览列表
     */
    @ResponseBody
    @RequestMapping(value = "/getBrowseList",method = RequestMethod.GET)
    @ApiOperation(value = "查询浏览列表", notes = "查询浏览列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "页码", dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "limit", value = "每页数量", dataType = "Integer", paramType = "query")
    })
    public ResponseData getBrowseList(BrowseParam param) {
        try{
            long memberId=MemberTokenUtil.getMemberId();
            if (param.getType()==0){//用户
                param.setMemberId(memberId);
            }else{//企业
                param.setComMemberId(memberId);
            }
            param.setMemberId(memberId);
            LayuiPageInfo pageInfo= browseService.findPageBySpec(param);
            return ResponseData.success(pageInfo);
        }catch (Exception e){
            return ResponseData.error(e.getMessage());
        }
    }

    /**
     * 查询看过我列表
     */
    @ResponseBody
    @RequestMapping(value = "/getVisitList",method = RequestMethod.GET)
    @ApiOperation(value = "查询看过我列表", notes = "查询看过我列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "页码", dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "limit", value = "每页数量", dataType = "Integer", paramType = "query")
    })
    public ResponseData getVisitList(BrowseParam param) {
        try{
            long memberId=MemberTokenUtil.getMemberId();
            if (param.getType()==0){//企业端
                param.setComMemberId(memberId);
            }else{//用户端
                param.setMemberId(memberId);
            }
            LayuiPageInfo pageInfo= browseService.findPageBySpec2(param);
            return ResponseData.success(pageInfo);
        }catch (Exception e){
            return ResponseData.error(e.getMessage());
        }
    }


    /**
     * 查询浏览详情
     */
    @ResponseBody
    @RequestMapping(value = "/getBrowseDetail",method = RequestMethod.GET)
    @ApiOperation(value = "查询浏览详情", notes = "查询浏览详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", required = true, paramType = "query")
    })
    public ResponseData getBrowseDetail(Long id) {
        BrowseParam param1=new BrowseParam();
        param1.setId(id);
        BrowseResult result=browseService.findBySpec(param1);
        return ResponseData.success(result);
    }

    /**
     * 添加/更新浏览
     */
    @ResponseBody
    @RequestMapping(value = "/addOrUpdateBrowse",method = RequestMethod.POST)
    @ApiOperation(value = "添加/更新浏览", notes = "添加/更新浏览")
    public ResponseData addOrUpdateBrowse(@RequestBody BrowseParam param) {
        try {
            long memberId=MemberTokenUtil.getMemberId();
            if (param.getType()==1){//企业端浏览记录
                param.setComMemberId(memberId);
            }else{
                param.setMemberId(memberId);
            }
            browseService.update(param);
            return ResponseData.success();
        }catch (Exception e){
            return ResponseData.error(e.getMessage());
        }
    }

    /**
     * 删除简历浏览
     */
    @ResponseBody
    @RequestMapping(value = "/deleteBrowse",method = RequestMethod.POST)
    @ApiOperation(value = "删除浏览", notes = "删除浏览")
    public ResponseData deleteBrowse(@RequestBody BrowseParam param) {
        try {
            browseService.removeById(param.getId());
            return ResponseData.success();
        }catch (Exception e){
            return ResponseData.error(e.getMessage());
        }
    }

}



